package com.haoran.dwz.config.util;

import org.springframework.stereotype.Component;

import com.netflix.config.DynamicBooleanProperty;
import com.netflix.config.DynamicContextualProperty;
import com.netflix.config.DynamicDoubleProperty;
import com.netflix.config.DynamicIntProperty;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;

@Component
public class DynamicProperties {

	public String getString(String key, String defaultValue) {
		DynamicStringProperty dsp = DynamicPropertyFactory.getInstance().getStringProperty(key, defaultValue);
		return dsp.get();
	}
	
	public int getInt(String key, int defaultValue) {
		DynamicIntProperty dbp = DynamicPropertyFactory.getInstance().getIntProperty(key, defaultValue);
		return dbp.get();
	}

	
	public boolean getBoolean(String key, boolean defaultValue) {
		DynamicBooleanProperty dbp = DynamicPropertyFactory.getInstance().getBooleanProperty(key, defaultValue);
		return dbp.get();
	}

	public double getDouble(String key, double defaultValue) {
		DynamicDoubleProperty  ddp = DynamicPropertyFactory.getInstance().getDoubleProperty(key, defaultValue);
		return ddp.get();
	}

	public <T> T getT(String key, T defaultValue) {
		DynamicContextualProperty<T>  ddp = DynamicPropertyFactory.getInstance().getContextualProperty(key, defaultValue);;
		return  ddp.getValue();
	}
}
